package com.gdkj.tencent;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.dingtalk.api.response.CorpReportListResponse;
import com.gdkj.constant.IMConstant;
import com.gdkj.enums.ImTargetEnums;
import lombok.Data;

@Data
public class IMBaseMessage {

    private IMMessageEntity msg;

    @JSONField(name = "retcode")
    private String retCode;

    private Integer target;

    @JSONField(name = "retmsg")
    private String retMsg;

    @JSONField(name = "touid")
    private String toUid;

    public IMBaseMessage() {
    }
    
    public IMBaseMessage( String retCode, Integer target, String retMsg, String toUid, String method, String action, Object data) {
        IMMessageEntity msg = new IMMessageEntity();
        msg.setAction("0");
        msg.setData(data);
        msg.setMethod(method);
        msg.setAction(action);
        this.msg = msg;
        this.retCode = retCode;
        this.target = target;
        this.retMsg = retMsg;
        this.toUid = toUid;
    }

    public IMBaseMessage(Integer target,  String toUid, String method,  Object data) {
        IMMessageEntity msg = new IMMessageEntity();
        msg.setAction("0");
        msg.setData(data);
        msg.setMethod(method);
        this.msg = msg;
        this.retCode = IMConstant.IM_SUCCESS_CODE;
        this.target = target;
        this.retMsg = IMConstant.IM_SUCCESS_MSG;
        this.toUid = toUid;
    }

    public IMBaseMessage(String retCode, String retMsg,Integer target,String toUid,String method,Object data) {
        IMMessageEntity msg = new IMMessageEntity();
        msg.setAction("0");
        msg.setData(data);
        msg.setMethod(method);
        this.msg = msg;
        this.retCode = retCode;
        this.target = target;
        this.retMsg = retMsg;
        this.toUid = toUid;
    }

    /**
    * 默认成功所用用户通知
    */
    public static IMBaseMessage getBaseMessage(String method, Object data){
        return new IMBaseMessage(ImTargetEnums.TARGET_TO_ALL.getState(),null,method,data);
    }

    /**
    * 默认成功特定用户通知
    */
    public static IMBaseMessage getBaseMessage(String method, Object data,Integer target,String toUid){
        return new IMBaseMessage(target,toUid,method,data);
    }

    /**
    * 默认异常
    */
    public static IMBaseMessage getErrorBaseMessage(String retCode,String retMsg,String method, Object data,Integer target,String toUid){
        return new IMBaseMessage(retCode,retMsg,target,toUid,method,data);
    }

    /**
    * 默认异常-所有用户通知
    */
    public static IMBaseMessage getErrorBaseMessage(String retCode,String retMsg,String method){
        return new IMBaseMessage(retCode,retMsg,ImTargetEnums.TARGET_TO_ALL.getState(),null,method,null);
    }
}
